/* eslint-disable */
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-canteens__stockorder}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getList()">
        <el-form-item>
          <el-date-picker
            v-model="dataForm.createDate"
            value-format="yyyy-MM-dd"
            type="month"
            :default-value="new Date()"
            placeholder="选择月"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.canteenId" placeholder="请选择">
            <el-option label="新食堂" value="1198803185855877122"></el-option>
            <el-option label="老食堂" value="1067246875800000066"></el-option>
          </el-select>
        </el-form-item>
           <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="getList()">{{ $t('query') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;"
      >
        <el-table-column prop="mealTime" label="用餐日期" header-align="center" align="center"></el-table-column>
        <el-table-column prop="canteenName" label="食堂" header-align="center" align="center"></el-table-column>
        <el-table-column prop="chedName" label="发起人" header-align="center" align="center"></el-table-column>
        <!-- <el-table-column prop="createDate" label="发起时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="estimateNum" label="预估用餐人数" header-align="center" align="center"></el-table-column> -->
        <el-table-column prop="practicalNum" label="实际用餐人数" header-align="center" align="center"></el-table-column>
        <el-table-column prop="canteenAdminName" label="审核人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="totalPrice" label="订单总额" header-align="center" align="center"></el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="toDetails(scope.row.stockOrderId)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @current-change="pageChange"
      ></el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
/* eslint-disable */
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./stockorder-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      status: ["已发起订单", "已审核", "已报价", "已验收", "主厨已确认", ""],
      mixinViewModuleOptions: {
        createdIsNeed: false,
        getDataListURL: "canteens/stockorder/getOrderList",
        getDataListIsPage: true,
        exportURL: "/canteens/stockorder/export",
        deleteURL: "/canteens/stockorder",
        deleteIsBatch: true,
        deleteIsBatchKey: "stockOrderId"
      },
      dataForm: {
        createDate: "",
        canteenId: "1198803185855877122"
      }
    };
  },

  beforeCreate: function() {},
  created: function() {
    this.dataForm.createDate = this.getNowFormatDate();
    this.getList();
  },
  methods: {
    getList() {
      this.$http
        .get(this.mixinViewModuleOptions.getDataListURL, {
          params: {
            order: this.order,
            orderField: this.orderField,
            page: this.mixinViewModuleOptions.getDataListIsPage
              ? this.page
              : null,
            limit: this.mixinViewModuleOptions.getDataListIsPage
              ? this.limit
              : null,
            ...this.dataForm
          }
        })
        .then(({ data: res }) => {
          this.total = res.totalPage;
          this.dataList = res.orderList;
        })
        .catch(() => {
          this.dataListLoading = false;
        });
    },
    pageChange(e) {
      this.dataForm.page = e;
      this.getList();
    },

    toDetails(e) {

        this.$router.push({ name: "canteens-stockordermx" ,params: { stockOrderId:e }},);
    },
    getNowFormatDate() {
      var date = new Date();
      var sign1 = "-";
      var sign2 = ":";
      var year = date.getFullYear(); // 年
      var month = date.getMonth() + 1; // 月
      var day = date.getDate(); // 日
      var hour = date.getHours(); // 时
      var minutes = date.getMinutes(); // 分
      var seconds = date.getSeconds(); //秒
      var weekArr = [
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六",
        "星期天"
      ];
      var week = weekArr[date.getDay()];
      // 给一位数数据前面加 “0”
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (day >= 0 && day <= 9) {
        day = "0" + day;
      }
      if (hour >= 0 && hour <= 9) {
        hour = "0" + hour;
      }
      if (minutes >= 0 && minutes <= 9) {
        minutes = "0" + minutes;
      }
      if (seconds >= 0 && seconds <= 9) {
        seconds = "0" + seconds;
      }
      var currentdate = year + sign1 + month + sign1 + day;

      return currentdate;
    }
  },
  components: {
    AddOrUpdate
  }
};
</script>
